package com.game.springbootstart.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.game.springbootstart.DTO.GamesDTO;
import com.game.springbootstart.config.QueryPageParam;
import com.game.springbootstart.entity.Games;
import com.game.springbootstart.mapper.GamesMapper;
import com.game.springbootstart.service.IGamesService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * <p>
 * 游戏表 服务实现类
 * </p>
 *
 * @author author
 * @since 2025-01-29
 */
@Service
public class GamesServiceImpl extends ServiceImpl<GamesMapper, Games> implements IGamesService {
    @Autowired
    private GamesMapper gamesMapper;

    @Override
    public List<String> getCategories() {
        List<String> list = gamesMapper.getCategories();
        return list;
    }

    @Override
    public List<Games> selectCategoryByName(String categoryName) {
        return gamesMapper.selectCategoryByName(categoryName);
    }

    @Override
    public List<Games> listByStatus() {
        return gamesMapper.listByStatus();
    }

    @Override
    public List<Games> searchGames(String keyword) {
        return gamesMapper.searchGames(keyword);
    }

    @Override
    public Games listId(Long id) {
        return gamesMapper.listId(id);
    }

    @Override
    public Long selectIdByName(String name) {
        return gamesMapper.selectIdByName(name);
    }

    public IPage<GamesDTO> listPage(QueryPageParam query) {
        HashMap param = query.getParam();
        String name = (String) param.get("name");
        Page<GamesDTO> page = new Page<>();
        page.setCurrent(query.getPageNum());
        page.setSize(query.getPageSize());
        return gamesMapper.selectGamesWithCategory(page, name);
    }

    @Override
    public List<String> lists() {
        return gamesMapper.selectGames();
    }
}
